
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gummworld2.pygame_utils</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="gummworld2.html"><font color="#ffffff">gummworld2</font></a>.pygame_utils</strong></big></big> (version $Id: pygame_utils.py 254 2011-02-27 08:24:02Z stabbingfinger@gmail.com $)</font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:///C:/cygwin/home/bw/devel/python/svn/gummworld2/gamelib/gummworld2/pygame_utils.py">c:\cygwin\home\bw\devel\python\svn\gummworld2\gamelib\gummworld2\pygame_utils.py</a></font></td></tr></table>
    <p><tt>pygame_utils.py&nbsp;-&nbsp;Collection&nbsp;of&nbsp;pygame&nbsp;utilities&nbsp;for&nbsp;Gummworld2.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="imp.html">imp</a><br>
<a href="os.html">os</a><br>
</td><td width="25%" valign=top><a href="pygame.html">pygame</a><br>
<a href="re.html">re</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-atan2"><strong>atan2</strong></a>(...)</dt><dd><tt><a href="#-atan2">atan2</a>(y,&nbsp;x)<br>
&nbsp;<br>
Return&nbsp;the&nbsp;arc&nbsp;tangent&nbsp;(measured&nbsp;in&nbsp;radians)&nbsp;of&nbsp;y/x.<br>
Unlike&nbsp;atan(y/x),&nbsp;the&nbsp;signs&nbsp;of&nbsp;both&nbsp;x&nbsp;and&nbsp;y&nbsp;are&nbsp;considered.</tt></dd></dl>
 <dl><dt><a name="-calc_line"><strong>calc_line</strong></a>(p0, p1)</dt><dd><tt>use&nbsp;Bresenham's&nbsp;algorithm&nbsp;to&nbsp;calculate&nbsp;a&nbsp;set&nbsp;of&nbsp;closed&nbsp;points&nbsp;forming&nbsp;a&nbsp;line<br>
&nbsp;<br>
Returns&nbsp;an&nbsp;array&nbsp;whose&nbsp;elements&nbsp;are&nbsp;the&nbsp;points&nbsp;of&nbsp;the&nbsp;line.<br>
&nbsp;<br>
Original&nbsp;calc_line&nbsp;code&nbsp;retrieved&nbsp;from:<br>
<a href="http://en.literateprograms.org/Bresenham's_line_algorithm_(Python)?oldid=16281">http://en.literateprograms.org/Bresenham's_line_algorithm_(Python)?oldid=16281</a></tt></dd></dl>
 <dl><dt><a name="-calculate_bezier"><strong>calculate_bezier</strong></a>(p, steps<font color="#909090">=30</font>)</dt><dd><tt>calculate&nbsp;a&nbsp;bezier&nbsp;curve&nbsp;from&nbsp;4&nbsp;control&nbsp;points<br>
&nbsp;<br>
Returns&nbsp;a&nbsp;list&nbsp;of&nbsp;the&nbsp;resulting&nbsp;points.<br>
&nbsp;<br>
The&nbsp;function&nbsp;uses&nbsp;the&nbsp;forward&nbsp;differencing&nbsp;algorithm&nbsp;described&nbsp;here:&nbsp;<br>
<a href="http://www.niksula.cs.hut.fi/~hkankaan/Homepages/bezierfast.html">http://www.niksula.cs.hut.fi/~hkankaan/Homepages/bezierfast.html</a><br>
&nbsp;<br>
This&nbsp;code&nbsp;taken&nbsp;from&nbsp;www.pygame.org/wiki/BezierCurve.</tt></dd></dl>
 <dl><dt><a name="-ccw_corners"><strong>ccw_corners</strong></a>(r)</dt><dd><tt>return&nbsp;a&nbsp;tuple&nbsp;containing&nbsp;the&nbsp;corners&nbsp;of&nbsp;rect&nbsp;r&nbsp;in&nbsp;counter-clockwise<br>
order&nbsp;starting&nbsp;with&nbsp;topleft</tt></dd></dl>
 <dl><dt><a name="-cos"><strong>cos</strong></a>(...)</dt><dd><tt><a href="#-cos">cos</a>(x)<br>
&nbsp;<br>
Return&nbsp;the&nbsp;cosine&nbsp;of&nbsp;x&nbsp;(measured&nbsp;in&nbsp;radians).</tt></dd></dl>
 <dl><dt><a name="-cw_corners"><strong>cw_corners</strong></a>(r)</dt><dd><tt>return&nbsp;a&nbsp;tuple&nbsp;containing&nbsp;the&nbsp;corners&nbsp;of&nbsp;rect&nbsp;r&nbsp;in&nbsp;clockwise&nbsp;order<br>
starting&nbsp;with&nbsp;topleft</tt></dd></dl>
 <dl><dt><a name="-degrees"><strong>degrees</strong></a>(...)</dt><dd><tt><a href="#-degrees">degrees</a>(x)<br>
&nbsp;<br>
Convert&nbsp;angle&nbsp;x&nbsp;from&nbsp;radians&nbsp;to&nbsp;degrees.</tt></dd></dl>
 <dl><dt><a name="-distance"><strong>distance</strong></a>(a, b)</dt><dd><tt>Calculate&nbsp;the&nbsp;distance&nbsp;between&nbsp;points&nbsp;a&nbsp;and&nbsp;b.&nbsp;Returns&nbsp;distance&nbsp;as&nbsp;a&nbsp;float.<br>
&nbsp;<br>
The&nbsp;a&nbsp;argument&nbsp;is&nbsp;a&nbsp;sequence&nbsp;representing&nbsp;one&nbsp;end&nbsp;point&nbsp;(x1,y1).<br>
&nbsp;<br>
The&nbsp;b&nbsp;argument&nbsp;is&nbsp;a&nbsp;sequence&nbsp;representing&nbsp;the&nbsp;other&nbsp;end&nbsp;point&nbsp;(x2,y2).</tt></dd></dl>
 <dl><dt><a name="-draw_text"><strong>draw_text</strong></a>(image, text, pos<font color="#909090">=(0, 0)</font>, font<font color="#909090">='default'</font>, fg<font color="#909090">=(254, 254, 254)</font>, bg<font color="#909090">=(-1, -1, -1)</font>, rect_attr<font color="#909090">=('left', 'top')</font>)</dt><dd><tt>Render&nbsp;text&nbsp;on&nbsp;the&nbsp;image&nbsp;in&nbsp;the&nbsp;named&nbsp;font.<br>
&nbsp;<br>
Text&nbsp;is&nbsp;rendered&nbsp;at&nbsp;pos&nbsp;in&nbsp;foreground&nbsp;color&nbsp;fg.&nbsp;Width&nbsp;and&nbsp;height&nbsp;of<br>
the&nbsp;rendered&nbsp;text&nbsp;is&nbsp;returned.&nbsp;rect_attr&nbsp;are&nbsp;the&nbsp;position&nbsp;attributes<br>
of&nbsp;the&nbsp;resulting&nbsp;rect&nbsp;to&nbsp;set&nbsp;equal&nbsp;to&nbsp;pos.</tt></dd></dl>
 <dl><dt><a name="-fill_gradient"><strong>fill_gradient</strong></a>(surface, color, gradient, rect<font color="#909090">=None</font>, vertical<font color="#909090">=True</font>, forward<font color="#909090">=True</font>)</dt><dd><tt>fill&nbsp;a&nbsp;surface&nbsp;with&nbsp;a&nbsp;gradient&nbsp;pattern<br>
Parameters:<br>
surface&nbsp;-&gt;&nbsp;drawing&nbsp;surface<br>
color&nbsp;-&gt;&nbsp;starting&nbsp;color<br>
gradient&nbsp;-&gt;&nbsp;final&nbsp;color<br>
rect&nbsp;-&gt;&nbsp;area&nbsp;to&nbsp;fill;&nbsp;default&nbsp;is&nbsp;surface's&nbsp;rect<br>
vertical&nbsp;-&gt;&nbsp;True=vertical;&nbsp;False=horizontal<br>
forward&nbsp;-&gt;&nbsp;True=forward;&nbsp;False=reverse<br>
&nbsp;<br>
Pygame&nbsp;recipe:&nbsp;<a href="http://www.pygame.org/wiki/GradientCode">http://www.pygame.org/wiki/GradientCode</a></tt></dd></dl>
 <dl><dt><a name="-get_font"><strong>get_font</strong></a>(name<font color="#909090">='default'</font>)</dt><dd><tt>Return&nbsp;the&nbsp;named&nbsp;pygame.font.<br>
&nbsp;<br>
The&nbsp;named&nbsp;font&nbsp;is&nbsp;looked&nbsp;up&nbsp;in&nbsp;cached&nbsp;fonts.&nbsp;The&nbsp;font&nbsp;named&nbsp;'default'<br>
is&nbsp;always&nbsp;available.&nbsp;See&nbsp;<a href="#-make_font">make_font</a>()&nbsp;for&nbsp;adding&nbsp;custom&nbsp;fonts&nbsp;to&nbsp;the<br>
cache.</tt></dd></dl>
 <dl><dt><a name="-get_font_names"><strong>get_font_names</strong></a>()</dt><dd><tt>Return&nbsp;a&nbsp;list&nbsp;of&nbsp;existing&nbsp;font&nbsp;names.</tt></dd></dl>
 <dl><dt><a name="-get_main_dir"><strong>get_main_dir</strong></a>()</dt><dd><tt>Intelligently&nbsp;find&nbsp;the&nbsp;directory&nbsp;the&nbsp;executable&nbsp;is&nbsp;in&nbsp;-&nbsp;needed&nbsp;for&nbsp;py2exe<br>
compatibility</tt></dd></dl>
 <dl><dt><a name="-import_module"><strong>import_module</strong></a>(fullname)</dt><dd><tt>Dynamically&nbsp;imports&nbsp;a&nbsp;module&nbsp;by&nbsp;name<br>
&nbsp;<br>
fullname&nbsp;is&nbsp;a&nbsp;string&nbsp;in&nbsp;any&nbsp;of&nbsp;these&nbsp;syntaxes:<br>
1.&nbsp;A&nbsp;file&nbsp;name&nbsp;in&nbsp;the&nbsp;Python&nbsp;path,&nbsp;with&nbsp;or&nbsp;without&nbsp;.py&nbsp;extension.<br>
2.&nbsp;Relative&nbsp;or&nbsp;absolute&nbsp;path&nbsp;and&nbsp;file,&nbsp;with&nbsp;or&nbsp;without&nbsp;.py&nbsp;extension.&nbsp;If<br>
path&nbsp;contains&nbsp;os.pathsep,&nbsp;the&nbsp;Python&nbsp;path&nbsp;is&nbsp;not&nbsp;used&nbsp;to&nbsp;locate&nbsp;the&nbsp;file.<br>
A&nbsp;relative&nbsp;path&nbsp;is&nbsp;relative&nbsp;to&nbsp;the&nbsp;current&nbsp;working&nbsp;directory.</tt></dd></dl>
 <dl><dt><a name="-init_joystick"><strong>init_joystick</strong></a>(joy_id<font color="#909090">=-1</font>)</dt><dd><tt>Initialize&nbsp;joysticks.&nbsp;This&nbsp;must&nbsp;be&nbsp;called&nbsp;before&nbsp;PyGame&nbsp;will<br>
start&nbsp;sending&nbsp;joystick&nbsp;events.&nbsp;If&nbsp;joy_id&nbsp;is&nbsp;-1&nbsp;all&nbsp;joysticks<br>
will&nbsp;be&nbsp;intialized.&nbsp;The&nbsp;initialized&nbsp;joysticks&nbsp;are&nbsp;returned&nbsp;as&nbsp;a<br>
dict&nbsp;keyed&nbsp;by&nbsp;joystick&nbsp;id.</tt></dd></dl>
 <dl><dt><a name="-load_image"><strong>load_image</strong></a>(name, colorkey<font color="#909090">=None</font>, alpha<font color="#909090">=False</font>)</dt><dd><tt>load&nbsp;an&nbsp;image&nbsp;into&nbsp;memory</tt></dd></dl>
 <dl><dt><a name="-make_font"><strong>make_font</strong></a>(name, file_name, font_size, bold<font color="#909090">=False</font>, italic<font color="#909090">=False</font>)</dt><dd><tt>Create&nbsp;a&nbsp;pygame.font.Font&nbsp;from&nbsp;a&nbsp;file.&nbsp;Return&nbsp;the&nbsp;font&nbsp;object.<br>
&nbsp;<br>
An&nbsp;instance&nbsp;of&nbsp;pygame.font.Font&nbsp;is&nbsp;created&nbsp;and&nbsp;stored&nbsp;in&nbsp;a&nbsp;cache&nbsp;for<br>
retrieval&nbsp;by&nbsp;<a href="#-get_font">get_font</a>().&nbsp;Initially&nbsp;there&nbsp;is&nbsp;one&nbsp;font&nbsp;named&nbsp;'default',<br>
which&nbsp;may&nbsp;be&nbsp;replaced&nbsp;by&nbsp;a&nbsp;custom&nbsp;font&nbsp;via&nbsp;this&nbsp;function&nbsp;if&nbsp;desired.<br>
Arguments&nbsp;mirror&nbsp;those&nbsp;of&nbsp;pygame.font.SysFont().</tt></dd></dl>
 <dl><dt><a name="-make_sysfont"><strong>make_sysfont</strong></a>(name, font_name, font_size, bold<font color="#909090">=False</font>, italic<font color="#909090">=False</font>)</dt><dd><tt>Create&nbsp;a&nbsp;pygame.font.Font&nbsp;from&nbsp;system&nbsp;fonts.&nbsp;Return&nbsp;the&nbsp;font&nbsp;object.<br>
&nbsp;<br>
An&nbsp;instance&nbsp;of&nbsp;pygame.font.Font&nbsp;is&nbsp;created&nbsp;and&nbsp;stored&nbsp;in&nbsp;a&nbsp;cache&nbsp;for<br>
retrieval&nbsp;by&nbsp;<a href="#-get_font">get_font</a>().&nbsp;Initially&nbsp;there&nbsp;is&nbsp;one&nbsp;font&nbsp;named&nbsp;'default',<br>
which&nbsp;may&nbsp;be&nbsp;replaced&nbsp;by&nbsp;a&nbsp;custom&nbsp;font&nbsp;via&nbsp;this&nbsp;function&nbsp;if&nbsp;desired.<br>
Arguments&nbsp;mirror&nbsp;those&nbsp;of&nbsp;pygame.font.SysFont().</tt></dd></dl>
 <dl><dt><a name="-plot_curve"><strong>plot_curve</strong></a>(p)</dt><dd><tt>plot&nbsp;a&nbsp;curved&nbsp;path&nbsp;along&nbsp;one&nbsp;or&nbsp;more&nbsp;sets&nbsp;of&nbsp;control&nbsp;points<br>
&nbsp;<br>
p&nbsp;is&nbsp;a&nbsp;one-dimensional&nbsp;array&nbsp;of&nbsp;points&nbsp;in&nbsp;multiples&nbsp;of&nbsp;four:&nbsp;i.e.<br>
four&nbsp;points&nbsp;per&nbsp;curve.<br>
&nbsp;<br>
steps&nbsp;is&nbsp;the&nbsp;number&nbsp;of&nbsp;points&nbsp;desired.&nbsp;steps&nbsp;is&nbsp;weighted&nbsp;by&nbsp;the&nbsp;sum<br>
distance&nbsp;of&nbsp;each&nbsp;four&nbsp;points&nbsp;in&nbsp;order&nbsp;to&nbsp;yield&nbsp;approximately<br>
equidistant&nbsp;points.<br>
&nbsp;<br>
This&nbsp;code&nbsp;derived&nbsp;from&nbsp;www.pygame.org/wiki/BezierCurve.</tt></dd></dl>
 <dl><dt><a name="-pow"><strong>pow</strong></a>(...)</dt><dd><tt><a href="#-pow">pow</a>(x,&nbsp;y)<br>
&nbsp;<br>
Return&nbsp;x**y&nbsp;(x&nbsp;to&nbsp;the&nbsp;power&nbsp;of&nbsp;y).</tt></dd></dl>
 <dl><dt><a name="-radians"><strong>radians</strong></a>(...)</dt><dd><tt><a href="#-radians">radians</a>(x)<br>
&nbsp;<br>
Convert&nbsp;angle&nbsp;x&nbsp;from&nbsp;degrees&nbsp;to&nbsp;radians.</tt></dd></dl>
 <dl><dt><a name="-rot_center"><strong>rot_center</strong></a>(image, angle)</dt><dd><tt>rotate&nbsp;an&nbsp;image&nbsp;while&nbsp;keeping&nbsp;its&nbsp;center&nbsp;and&nbsp;size</tt></dd></dl>
 <dl><dt><a name="-sign"><strong>sign</strong></a>(n)</dt><dd><tt>return&nbsp;the&nbsp;sign&nbsp;of&nbsp;number&nbsp;n</tt></dd></dl>
 <dl><dt><a name="-sin"><strong>sin</strong></a>(...)</dt><dd><tt><a href="#-sin">sin</a>(x)<br>
&nbsp;<br>
Return&nbsp;the&nbsp;sine&nbsp;of&nbsp;x&nbsp;(measured&nbsp;in&nbsp;radians).</tt></dd></dl>
 <dl><dt><a name="-split_thousands"><strong>split_thousands</strong></a>(s, sep<font color="#909090">=','</font>)</dt><dd><tt>insert&nbsp;a&nbsp;comma&nbsp;every&nbsp;thousands&nbsp;place</tt></dd></dl>
 <dl><dt><a name="-sqrt"><strong>sqrt</strong></a>(...)</dt><dd><tt><a href="#-sqrt">sqrt</a>(x)<br>
&nbsp;<br>
Return&nbsp;the&nbsp;square&nbsp;root&nbsp;of&nbsp;x.</tt></dd></dl>
 <dl><dt><a name="-wait_event"><strong>wait_event</strong></a>(type<font color="#909090">=5</font>)</dt></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>MOUSEBUTTONDOWN</strong> = 5<br>
<strong>RLEACCEL</strong> = 16384<br>
<strong>__author__</strong> = 'Gummbum, (c) 2011'<br>
<strong>__version__</strong> = '$Id: pygame_utils.py 254 2011-02-27 08:24:02Z stabbingfinger@gmail.com $'<br>
<strong>pi</strong> = 3.1415926535897931</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
    
<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Gummbum,&nbsp;(c)&nbsp;2011</td></tr></table>
</body></html>